package lib;

import java.util.Date;
import java.util.Vector;

import model.StaticInstances;


public class Bill 
{
	private int billID;
	private String category, type;
	private String company, name;
	private Vector transactionsPaid; 
	private Vector transactionsIncured;
	private double amountOwed;
	
	public Bill(String category, String type, String company, String name )
	{
		this.category = category;
		this.type = type; // either Fixed or Recurring
		this.company = company;
		this.name = name;
		amountOwed = 0;
		
		transactionsIncured = new Vector();
		transactionsPaid = new Vector();
		
		setBillID(-1);
	}
	
	public void addBillIncured(Date date, double amount)
	{
		Transaction transaction = new Transaction(date, amount);
		transactionsIncured.addElement(transaction);
		
		amountOwed += transaction.getAmount();
	}
	
	public void addPaymentMade(Date date, double amount)
	{
		Transaction transaction = new Transaction(date, amount);
		transactionsPaid.addElement(transaction);
		
		amount -= transaction.getAmount();
	}
	
	public boolean isOwing()
	{
		return amountOwed > 0;
	}
	
	public String title()
	{
		return name != null && name.length() > 0? name : company;
	}

	public String getAmountOwed()
	{
		return StaticInstances.formatDecimal(amountOwed, 2);
	}

	public void setBillID(int billID) {
		this.billID = billID;
	}

	public int getBillID() {
		return billID;
	}
}
